from datetime import datetime

import pandas as pd
from sqlalchemy import Column, Integer
import sqlalchemy as sa
from infrastructure.model.base_model import BaseModel
from infrastructure.model.stock_kline import StockKline


class IndexKline(BaseModel):
    """
    指数日线行情
    """
    __tablename__ = 'index_kline'

    id = Column(Integer, primary_key=True, autoincrement=True)
    ts_code = sa.Column(sa.CHAR(9))
    trade_date = sa.Column(sa.DateTime())
    open = sa.Column(sa.Numeric(8, 2))
    high = sa.Column(sa.Numeric(8, 2))
    low = sa.Column(sa.Numeric(8, 2))
    close = sa.Column(sa.Numeric(8, 2))
    volume = sa.Column(sa.BigInteger)



if __name__ == '__main__':
    df = pd.DataFrame({
        'ts_code': ['000001.SZ'],
        'trade_date': [datetime.now().astimezone().date().strftime('%Y-%m-%d')],
        'open': [10.0],
        'high': [10.0],
        'low': [10.0],
        'close': [11.0],
        'volume': [1000000]
    })
    IndexKline.save(df, index_elements=['id'])
